package com.scedu.springcloud.service;

import com.scedu.springcloud.entity.Dept;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;
/*
降级
 */
@Component
public class DeptClientServiceFallBackFactory implements FallbackFactory <DeptClientService> {
    //失败了就创建一个DeptClientService服务接口的实现类
    public DeptClientService create(Throwable throwable) {
        //应该 return new DeptClientService();
        //但是接口不能直接new，所以要重写接口的方法
        return new DeptClientService() {
            public Integer addDept(Dept dept) {
                return 0;
            }

            public Dept queryById(Long id) {
                return new Dept().setDeptno(id)
                        .setDbSource("no db")
                        .setDname("客户端提供了降级，服务已关闭。");

            }

            public List<Dept> queryALL() {
                return null;
            }
        };
    }
}
